#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "protocol/simple_protocol.h"

int heartbeat_impl(simple_protocol_t *ptr, void *userdata)
{
    if (ptr == NULL)
        return -1;
    printf("auth:%s heartbeat\n", ptr->auth);
    return 0;
}

int server_ac_impl(simple_protocol_t *ptr, void *userdata)
{
    if (ptr == NULL)
        return -1;
    printf("auth:%s ac(%d):%s\n", ptr->auth, ptr->len, ptr->data);
    if (userdata == NULL)
    {
        for (int j = 0; j < ptr->len; j++)
        {
            if (ptr->data[j] >= 'a' && ptr->data[j] <= 'z')
                ptr->data[j] = toupper(ptr->data[j]);
        }
    }
    else
    {
        char *str = (char *)userdata;
        int str_len = strlen(str);
        str_len = str_len > (SIMPLE_PROTOCOL_DATA_LEN - 1) ? SIMPLE_PROTOCOL_DATA_LEN : str_len;
        strncpy(ptr->data, str, str_len);
    }
    return 0;
}

int server_auth_impl(simple_protocol_t *ptr, void *userdata)
{
    if (ptr == NULL)
        return -1;

    return 0;
}